package com.buddies.lottery.ui.lottery;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.buddies.lottery.R;
import com.buddies.lottery.data.bean.Lottery;
import com.buddies.lottery.utils.LotteryUtils;
import com.buddies.lottery.widget.CountDownTimerView;
import com.buddies.lottery.widget.DotView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

public class LotteryCategoryAdapter extends BaseQuickAdapter<Lottery, BaseViewHolder> {

    public LotteryCategoryAdapter(@Nullable List<Lottery> data) {
        super(R.layout.item_lottery_category, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Lottery item) {
        ((SimpleDraweeView) helper.getView(R.id.image)).setImageURI(item.pic_url);

        helper.setText(R.id.tv_category, item.name);
        ((DotView)helper.getView(R.id.tv_win_num)).setDots(item.id, item.prev.getWinNum());
        helper.setText(R.id.tv_period, LotteryUtils.formatLotteryPeriod(item.prev.period));

        if (item.next != null) {
            helper.setText(R.id.tv_next_period, LotteryUtils.formatLotteryNextPeriod(item.next.period_show));

            CountDownTimerView timerView = helper.getView(R.id.timer);
            timerView.bindView((TextView) helper.getView(R.id.tv_next_period), (TextView) helper.getView(R.id.status));
            timerView.setTime(item, item.next.getOpenTimeDelta());
            timerView.startCountDown();
        }
    }

}
